package com.house.house.web;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.house.customer.common.ExtPageable;
import com.house.house.entity.House;
import com.house.house.entity.Owner;
import com.house.house.entity.dto.HouseDto;
import com.house.house.entity.dto.HouseQueryDto;
import com.house.house.service.IHouseService;
import com.house.house.service.IOwnerService;
import com.house.house.util.enums.Sex;
import com.house.house.util.enums.State;


@Controller
@RequestMapping("/house")
public class HouseController {
	@Autowired
	private IHouseService houseService;
	@Autowired
	private IOwnerService ownerService;
	
	@RequestMapping("/save")
	public @ResponseBody String save() {
		return null;
		
	}
	
	@RequestMapping("/findOne")
	public @ResponseBody HouseDto findOne(@RequestParam Long id) {
		House house = houseService.findOne(id);
		HouseDto houseDto = new HouseDto();
		houseDto.setHouse(house);
		Long ownerId = house.getOwner().getOwnerId();
		Owner owner = ownerService.findOne(ownerId);
		houseDto.setOwnerName(owner.getOwnerName());
		return houseDto;
		
	}
	
	@RequestMapping("/findAll")
	public @ResponseBody List<House> findAll() {
		List<House> list = houseService.findAll();
		return list;
		
	}
	
	@RequestMapping("/findPage")
	public @ResponseBody Page<House> findPage(HouseQueryDto houseQueryDto,ExtPageable extPageable) {
		Page<House> page = houseService.findPage(HouseQueryDto.getSpecification(houseQueryDto), extPageable.getPageable());
		return  page;	
	}
}
